<?php

defined('BASEPATH') or die('forbidden');

class Vip {

    function __construct() {
        $framework = &get_instance('controller');
        $this->db = &$framework->db;
        $this->cache = &$framework->cache;
    }

    function _init() {
        //加载缓存
        $result = $this->cache->get("vipdata");
        if (!$result) {
            $result = array();
            $this->db->query("SELECT * FROM {pre}vip");
            while ($row = $this->db->get_array()) {
                $result[$row['id']] = $row;
            }
            $this->cache->set("vipdata", $result);
        }
        $this->vipData = $result;
    }

    /**
     * 读取VIP信息
     * @param string $id
     * @return array
     */
    function get_vip($id) {
        if (is_array($id)) {
            $last = array();
            foreach ($id as $m => $n) {
                $last[$n] = isset($this->vipData[$n]) ? $this->vipData[$n] : array();
            }
        } else {
            $last = isset($this->vipData[$id]) ? $this->vipData[$id] : array();
        }
        return $last;
    }

}